package com.oschat.controller;

import com.oschat.annotation.GlobalInterceptor;
import com.oschat.entity.po.AppUpdate;
import com.oschat.entity.query.AppUpdateQuery;
import com.oschat.entity.vo.PaginationResultVO;
import com.oschat.entity.vo.ResponseVO;
import com.oschat.service.AppUpdateService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;

/**
 * @author 黄宏展
 * @version 1.0
 * @description: TODO
 * @date 2025/7/30 15:37
 */
@RestController("adminAppUpdateController")
@RequestMapping("/admin")
public class AdminAppUpdateController extends ABaseController {

    @Resource
    private AppUpdateService appUpdateService;


    @RequestMapping("/loadUpdateList")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO loadUpdateList(AppUpdateQuery query) {
        query.setOrderBy("id desc");
        PaginationResultVO resultVO = appUpdateService.findListByPage(query);
        return getSuccessResponseVO(resultVO );
    }

    @RequestMapping("/saveUpdate")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO saveUpdate(Integer id,
                                 @NotEmpty String version,
                                 @NotEmpty  String updateDesc,
                                 @NotNull Integer fileType,
                                 String outerLink,
                                 MultipartFile file
                                 ) throws IOException {
        AppUpdate appUpdate = new AppUpdate();
        appUpdate.setId(id);
        appUpdate.setVersion(version);
        appUpdate.setUpdateDesc(updateDesc);
        appUpdate.setFileType(fileType);
        appUpdate.setOuterLink(outerLink);
        appUpdateService.saveUpdate(appUpdate,file);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/delUpdate")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO delUpdate(@NotNull  Integer id){
        appUpdateService.deleteAppUpdateById(id);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/postUpdate")
    @GlobalInterceptor(checkAdmin = true)
    public ResponseVO postUpdate(@NotNull  Integer id,@NotNull Integer status,String grayscaleUid){
        appUpdateService.postUpdate(id,status,grayscaleUid);
        return getSuccessResponseVO(null);
    }

}
